import React, { Component, PropTypes } from 'react';
import { Modal, Button } from 'antd';
import noop from 'util/noop'

const  dialog = (WrappedComponent) => {
    return class Dialog extends Component {
        static defaultProps = {
            onOk:noop,
            onCancel:noop,
            visible:false,
            title:'',
        }

        constructor(props){
            super(props);
        }
        render(){
            const { 
                onOK, 
                onCancel,
                visible,
                title,
                ...other } = this.props;

            const defaultFooter = [(
                <Button
                    key="cancel"
                    size="large"
                    type="ghost"
                    onClick={this.handleCancel}
                >
                    关闭
                </Button>
            )]
            return (
                <Modal
                    title={title}
                    visible={visible}
                    onOk={onOK}
                    onCancel={onCancel}
                    footer={defaultFooter}
                >
                    <WrappedComponent {...other} />
                </Modal>
            )
        }

        handleCancel = (e) => {
            this.props.onCancel(e);
        }

        handleOk = (e) => {
            this.props.onOK(e)
        }
       
    }
}

export default dialog;

